import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import {
  ApiBody,
  ApiExtraModels,
  ApiOperation,
  ApiSecurity,
  ApiTags,
} from '@nestjs/swagger';
import { ApiQueryBodyRequest } from 'src/decorator/api-request.decorator';
import { ApiPaginatedResponse } from 'src/decorator/api-response.decorator';
import { BaseListResultModel } from 'src/logical/common/models/BaseListResult.model';
import { Pagination } from 'src/logical/common/models/Pagination.model';
import { QueryModel } from 'src/logical/common/models/Query.model';
import { loginLogModel } from '../models/loginLog.model';
import { loginLogDetailModel } from '../models/loginLogDetail.model';
import { LoginLogService } from '../service/login-log.service';

@ApiSecurity('Authorization')
@ApiTags('登录日志')
@ApiExtraModels(loginLogDetailModel, loginLogModel)
@Controller('/api/log/login')
export class LoginLogController {
  constructor(private readonly loginLogService: LoginLogService) {}

  @UseGuards(AuthGuard('jwt'))
  @ApiPaginatedResponse(loginLogDetailModel)
  @ApiBody(ApiQueryBodyRequest('queryModel', loginLogModel))
  @ApiOperation({ summary: '查询列表' })
  @Post('getLoginLogList')
  async getList(
    @Body() queryModel: QueryModel<loginLogModel, Pagination>,
  ): Promise<BaseListResultModel<Array<loginLogDetailModel>>> {
    return await this.loginLogService.queryForList(
      queryModel.query,
      queryModel.pagination,
    );
  }
}
